<template>
	<view class="container">
		<view class="h2-header"><text class="h2-ttl">请填写企业信息</text></view>

		<view class="row">
			<text class="tit">姓名</text>
			<input class="input" type="text" v-model="realName" placeholder="请输入姓名" />
		</view>
		<view class="row">
			<text class="tit">公司名称</text>
			<input class="input" type="text" v-model="sellerName" placeholder="请输入公司名称" />
		</view>
		<view class="row">
			<text class="tit">公司电话</text>
			<input class="input" type="text" v-model="companyPhone" placeholder="请输入公司电话" />
		</view>

		<view class="row">
			<text class="tit">经营范围</text>
			<picker class="tip" @change="scopeChange" :value="scope" :range="scope">
				<view class="uni-input">
					<text>{{scope[scopeIndex]}}</text>
					<text class="icon icon-arrow_right"></text>
				</view>
			</picker>
		</view>
		<view class="row">
			<text class="tit">法人姓名</text>
			<input class="input" type="text" v-model="legalPerson" placeholder="请输入法人姓名" />
		</view>
		<view class="row">
			<text class="tit">开票资料</text>
			<input class="input" type="text" v-model="invoiceInfo" placeholder="请输入开票资料" />
		</view>

		<view class="row area-row">
			<text class="tit">营业执照</text>
			<uni-upimg @change="getImageInfo01" :upimg_preview="licensePhoto" :upload_count="5"></uni-upimg>
		</view>
		<view class="row area-row">
			<text class="tit">资格证书</text>
			<uni-upimg @change="getImageInfo02" :upimg_preview="certificationsPhoto" :upload_count="5"></uni-upimg>
		</view>
		<view class="row area-row">
			<text class="tit">公司logo</text>
			<uni-upimg @change="getImageInfo03" :upimg_preview="logoPic" :upload_count="1"></uni-upimg>
		</view>

		<button type="primary" class="add-btn" @click="confirm" :disabled="submiting">提交</button>
	</view>
</template>

<script>
	import uniUpimg from '@/components/uni-upimg.vue'
	export default {
		components: {
			uniUpimg
		},
		data() {
			return {
				userType: '0',
				realName: '',
				companyPhone: '',
				sellerName: '',
				legalPerson: '',
				invoiceInfo: '',
				scope: ['聚氯乙烯', '聚乙烯', '聚丙烯', 'ABS', '再生颗粒', '助剂'],
				submiting: false,
				scopeIndex: 0,
				licensePhoto: [],
				certificationsPhoto: [],
				logoPic: []
			}
		},
		onLoad(option) {
			if (option) {
				this.userType = option.type
			}
		},
		methods: {
			scopeChange(e) {
				this.scopeIndex = e.target.value
			},
			getImageInfo01(e) {
				this.licensePhoto = e
			},
			getImageInfo02(e) {
				this.certificationsPhoto = e
			},
			getImageInfo03(e) {
				this.logoPic = e
			},
			//提交
			confirm() {
				if (!this.realName) {
					this.$api.msg('请输入姓名')
					return
				}
				if (!this.sellerName) {
					this.$api.msg('请输入公司名称')
					return
				}
				if (!this.companyPhone) {
					this.$api.msg('请输入公司电话')
					return
				}
				if (!this.legalPerson) {
					this.$api.msg('请输入法人姓名')
					return
				}
				if (!this.invoiceInfo) {
					this.$api.msg('请输入开票信息')
					return
				}
				if (!this.licensePhoto) {
					this.$api.msg('请上传营业执照')
					return
				}
				if (!this.certificationsPhoto) {
					this.$api.msg('请上传资格证书')
					return
				}
				this.submiting = true
				this.$api.request('/authen/addOrUpdateAuthen', {
					userType: this.userType,
					realName: this.realName,
					sellerName: this.sellerName,
					scope: this.scope[this.scopeIndex],
					companyPhone: this.companyPhone,
					legalPerson: this.legalPerson,
					invoiceInfo: this.invoiceInfo,
					licensePhoto: this.licensePhoto.join(','),
					certificationsPhoto: this.certificationsPhoto.join(','),
					logoPic: this.logoPic.join(',')
				}, {
					failback: failres => {
						this.submiting = false
						this.$api.msg(failres.message)
					}
				}).then(res => {
					//注册成功
					this.submiting = false
					this.$api.msg(res.message)
					setTimeout(() => {
						uni.redirectTo({
							url: `./step03`
						})
					}, 500)
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		padding-top: 20upx;
	}

	.row {
		.tit {
			width: 150upx;
		}

		.value {
			flex: 1;
		}

		.tip {
			flex-basis: 100%;
		}

		.uni-input {
			display: flex;
			justify-content: space-between;
		}
	}

	.area-row {
		height: inherit;
		padding: 20upx $base-row-spacing;
	}

	/* #ifdef H5 */
	@media screen and (min-width: 750px) {
		page {
			padding-top: 40px;
			margin: 0 auto;
			max-width: 750px;
		}

		.row {
			.tit {
				width: 150px;
			}
		}

		.area-row {
			height: inherit;
			padding: 20px 30px;
		}
	}

	/* #endif */
</style>
